package hbt;

//import java.util.List;

import org.hibernate.Session;
import org.hibernate.SessionFactory;

public class HibernateDAO {
	protected static HibernateDAO instancia = null;
	protected static SessionFactory sf = null;
	protected static Session session = null;
	
	public static HibernateDAO getInstancia(){
		if(instancia == null){
			instancia = new HibernateDAO();
		} 
		return instancia;
	}
	
	protected HibernateDAO()  {
		sf = HibernateFactory.getSessionFactory();
	}

	protected Session getSession(){
		if(session == null || !session.isOpen()){
			session = sf.openSession();
		}
		return session;
	}
	
	public void closeSession(){
		if (session.isOpen()) {
			session.close();
			System.out.println("\nOPEN: " + session.isOpen());
		}
	}
	
/*	
	@SuppressWarnings("unchecked")
	public List<Rubros> recuperarRubros(){
		Session session = getSession();
		List<Rubros> lista = session.createQuery("from Rubros").list();
		session.close();
		return  lista;
	}*/
}
